package com.rock.goc.data.exception;

import com.rock.common.exception.CodeEnum;
import com.rock.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理类
 */
@Slf4j
//@ResponseBody
//@ControllerAdvice(basePackages = {"com.rock.goc.data"})

@RestControllerAdvice(basePackages = {"com.rock.goc.data"})
public class RockExceptionControllerAdvice {

    @ExceptionHandler(value = Exception.class)
    public R exceptionHandler(Exception e){
        log.error("未知异常, 异常原因:{}, 异常类型:{}", e.getMessage(), e.getClass());
        return R.error(CodeEnum.UNKNOW_EXCEPTION.getCode(), CodeEnum.UNKNOW_EXCEPTION.getMsg());
    }

}
